package com.thread.exe;

import java.util.HashMap;
import java.util.Map;

public class BetterAttributeStore {
	private final Map<String, String> attr = new HashMap<String, String>();
	
	public boolean userLocationMatches(String name) {
		String location;
		synchronized (this) {
			location = attr.get(name);
		}
		try {
			Thread.sleep(2000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(location);
		return location == null;
	}
	
	public synchronized void set() {
		attr.put("1", "a");
	}
	
	private class StoreRunable extends Thread{

		public void run() {
			System.out.println(BetterAttributeStore.this.userLocationMatches("1"));
		}
		
	}
	public static void main(String[] args) {
		BetterAttributeStore bs = new BetterAttributeStore();
		Thread t1 = bs.new StoreRunable();
		t1.start();
		try {
			Thread.sleep(1000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		bs.set();
	}
}/**
*Output:
null
true
*/
